package com.qianfeng.openplatform.webmaster.controller;

import com.qianfeng.openplatform.webmaster.entry.LayuiDataTableSource;
import com.qianfeng.openplatform.webmaster.entry.OpenApiMaster;
import com.qianfeng.openplatform.webmaster.pojo.Customer;
import com.qianfeng.openplatform.webmaster.service.CustomerService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 江江
 * @Date 2020/7/22 17:28
 */
@RestController
@RequestMapping("/sys/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/table")
    public LayuiDataTableSource showTable(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,
                                          @RequestParam(required = false) String name, @RequestParam(defaultValue = "-1") Integer state){
     return customerService.getCusetomerPage(page,limit,name,state);
    }

    @RequestMapping("/add")
    public OpenApiMaster addCustomer(Customer customer){
        return customerService.addCustomer(customer);
    }

    @RequestMapping("/update")
    public OpenApiMaster update(Customer customer){
        return customerService.updateCustomer(customer);
    }

    @RequestMapping("/del")
    public OpenApiMaster del(String ids){
        System.out.println(ids);
        String[] arr= ids.split(",");
//        for (String s : arr) {
//            System.out.println(s);
//
//        }
        return customerService.delCustomer(arr);
    }
    @RequestMapping("/tree")
    public List<Customer> getCustomerTree(Customer customer){
        return customerService.getCustomerAll();
    }
}
